{% extends "page.html" %}

{% block title %}服务器管理{% endblock %}

{% block nav %} {{show_navs('server')}} {% endblock %}

{% block clientscript %}
	{{super()}}
	<script>
		function edit_server(id) {
		    $('#dlg').dialog({
						title: '服务器管理',
						width: 370,
						height: 320,
						closed: false,
						cache: false,
						modal: true
					});
				   $('#dlg').dialog('refresh','/edit_server'+(id?'/'+id:''));
		}

		function del_server(id) {
         $.messager.confirm("确认", "确定要删除访服务器吗?", function (r) {
                if (r) {
                    $.post("/del_server/"+id,function(data,status){
                    		if (data=='1') {
                    			$('#gri').datagrid('reload');
                    		} else {
                    			alert(data);
                    		}
                    });
                }
            });
		}

		function server_shell(id) {
			window.open("{{ url_for('server_shell') }}?id="+id,"_blank");
		}

		function op_fmt(val,row) {
			var s= '[<a href="javascript:void(0)" onclick="edit_server('+row.id+')">编辑</a>]&nbsp;&nbsp;'+
                '[<a href="javascript:void(0)" onclick="del_server('+row.id+')">删除</a>]&nbsp;&nbsp;'+
                '[<a href="javascript:void(0)" onclick="server_shell('+row.id+')">shell</a>]';
			return s;		
		}
	</script>
{% endblock clientscript %}

{% block content %}
<div id="tb" style="padding:3px">
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onclick="edit_server()">添加服务器</a>
     </div>
    {% from "snippet.html" import render_field %}
    <div id="dlg" closed="true" class="easyui-dialog" data-options="buttons: [{
            text:'确定',
            iconCls:'icon-ok',
            handler:function(){
                $.ajax({
                    type: 'post',
                    url: $('#form_post').attr('action'),
                    data:$('#form_post').serialize(),
                    dataType: 'text',
                    success: function(data,textStatus){
                        if (data=='1'){
                            $('#gri').datagrid('reload');
                            $('#dlg').dialog('close');
                        } else {
                            $.messager.alert('错误',data,'error');
                        }

                    },
                    error: function(err){
                        //请求出错处理
                        $.messager.alert('错误','操作失败,请稍后重试!','error');
                    }
                });
            }
        },{

            text:'取消',
            iconCls:'icon-cancel',
            handler:function(){
                $('#dlg').dialog('close');
            }
        }]">
    </div>

    <div class='grid'>
	    <table id="gri" class="easyui-datagrid" style="height:600px"
	            url="{{ url_for('qry_server_data') }}"
	            title=""
	            toolbar="#tb"
	            singleSelect="true"
	            pageSize="20"
	            fitColumns="true"
	            rownumbers="true" pagination="true">
	        <thead>
	            <tr>
	                <th field="host" width="20">主机名</th>
	                <th field="port" width="10">端口</th>
						 <th field="user" width="10">用户名</th>
						 <th field="remark" width="30">备注</th>
						 <th field="op" formatter="op_fmt" width="20">操作</th>
	            </tr>
	        </thead>
	    </table>
    </div>
{% endblock content %}